﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TrucTiepService
{
    public class Extension
    {
        public static IEnumerable<T> bindDataTreeView<T>(T root, Func<T, IEnumerable<T>> childerns)
        {
            var q = new Queue<T>();
            q.Enqueue(root);
            while (q.Count > 0)
            {
                T current = q.Dequeue();
                yield return current;
                foreach (var child in childerns(current))
                    q.Enqueue(child);
            }
        }
    }
}